<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/3/18
 * Time: 13:07
 * Mail:87658989@qq.com
 */

namespace app\api\behavior;

use app\base\logic;
use think\Db;
class Push
{
    public $push;

    public function __construct()
    {
        $this->push = new logic\Push();
    }

    public function changeDevice(&$params){
        $type = $params['type'];
        $id   = $params['id'];
        $msg  = !empty($params['msg']) ? $params['msg'] : '其他设备';
        // $pid  = $params['pid']; 备用
        $data = ['action'=>'chane_device'];
        $notice = '您的账号在'.$msg.'登入';
        $type == 'passenger' && $this->push->pushPassenger([$id],$data,$notice);
        $type == 'driver' && $this->push->pushDriver([$id],$data,$notice);
    }

    public function sendMessageNoticePassenger($pid=0,$msg=[],$notice=''){
        $pushId = Db::name('passenger')->alias('a')
            ->join('push_bind b','a.user_id = b.user_id and b.use_type = 2')
            ->where('a.passenger_id',$pid)
            ->value('push_user_id');
        $this->push->pushPassenger([$pushId],json_encode($msg),$notice);
    }

    public function sendMessageNoticeDriver($did=0,$msg=[],$notice=''){
        $pushId = Db::name('driver')->alias('a')
            ->join('push_bind b','a.user_id = b.user_id and b.use_type = 1')
            ->where('a.driver_id',$did)
            ->value('push_user_id');
        $this->push->pushDriver([$pushId],json_encode($msg),$notice);
    }
}